home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / colorlab / modinism.bas < prev    next >
Encoding:
BASIC Source File  |  1999-09-24  |  3.3 KB  |  82 lines

  1. Attribute VB_Name = "modINI"
  2. Option Explicit
  3. Declare Function GetPrivateProfileStringByKey _
  4.     Lib "kernel32" Alias "GetPrivateProfileStringA" _
  5.     (ByVal lpApplicationName As String, ByVal lpKeyName As String, _
  6.     ByVal lpDefault As String, ByVal lpReturnedString As String, _
  7.     ByVal nSize As Long, ByVal lpFileName As String) As Long
  8.  
  9. Declare Function GetPrivateProfileStringKeys _
  10.     Lib "kernel32" Alias "GetPrivateProfileStringA" _
  11.     (ByVal lpApplicationName As String, ByVal lpKeyName As Long, _
  12.     ByVal lpDefault As String, ByVal lpReturnedString As String, _
  13.     ByVal nSize As Long, ByVal lpFileName As String) As Long
  14.  
  15. Declare Function GetPrivateProfileStringSections _
  16.     Lib "kernel32" Alias "GetPrivateProfileStringA" _
  17.     (ByVal lpApplicationName As Long, ByVal lpKeyName As Long, _
  18.     ByVal lpDefault As String, ByVal lpReturnedString As String, _
  19.     ByVal nSize As Long, ByVal lpFileName As String) As Long
  20.  
  21. Declare Function GetPrivateProfileInt _
  22.     Lib "kernel32" Alias "GetPrivateProfileIntA" _
  23.     (ByVal lpApplicationName As String, ByVal lpKeyName As String, _
  24.     ByVal nDefault As Long, ByVal lpFileName As String) As Long
  25.  
  26. Declare Function WritePrivateProfileStringByKey _
  27.     Lib "kernel32" Alias "WritePrivateProfileStringA" _
  28.     (ByVal lpApplicationName As String, ByVal lpKeyName As String, _
  29.     ByVal lpString As String, ByVal lpFileName As String) As Long
  30.     
  31. Declare Function WritePrivateProfileStringToDeleteKey _
  32.     Lib "kernel32" Alias "WritePrivateProfileStringA" _
  33.     (ByVal lpApplicationName As String, ByVal lpKeyName As String, _
  34.     ByVal lpString As Long, ByVal lpFileName As String) As Long
  35.  
  36. Declare Function GetPrivateProfileSection _
  37.     Lib "kernel32" Alias "GetPrivateProfileSectionA" _
  38.     (ByVal lpAppName As String, ByVal lpReturnedString As String, _
  39.     ByVal nSize As Long, ByVal lpFileName As String) As Long
  40.  
  41. Declare Function WritePrivateProfileSection _
  42.     Lib "kernel32" Alias "WritePrivateProfileSectionA" _
  43.     (ByVal lpAppName As String, ByVal lpString As String, _
  44.     ByVal lpFileName As String) As Long
  45.  
  46. Public Sub DeleteINIKey(Section As String, Key As String)
  47. Dim lReturn As Long
  48. 'deletes entire entry, not just value
  49.     lReturn = WritePrivateProfileStringToDeleteKey(Section, Key, 0&, "drqcr.ini")
  50.     
  51. End Sub
  52.  
  53. Public Sub WriteINI(Section As String, Key As String, ByVal KeyValue As String)
  54. Dim lReturn As Long
  55. 'writes value (creates entry if it doesn't exist)
  56.     lReturn = WritePrivateProfileStringByKey(Section, Key, KeyValue, "drqcr.ini")
  57. End Sub
  58.  
  59. Public Function GetINIString(Section As String, Key As String, Optional Default As String = "") As String
  60. Dim KeyValue As String, Characters As Long, intPos As Integer
  61. 'retrieves STRING value
  62.     KeyValue = String(256, 0)
  63.     
  64.     Characters = GetPrivateProfileStringByKey(Section, Key, Default, KeyValue, 255, "drqcr.ini")
  65.     
  66.     If Characters > 1 Then KeyValue = left$(KeyValue, Characters)
  67.     
  68.     intPos = InStr(KeyValue, Chr$(0) & Chr$(0))
  69.     
  70.     If intPos > 0 Then
  71.         KeyValue = left$(KeyValue, intPos - 1)
  72.     End If
  73.     
  74.     GetINIString = KeyValue
  75.  
  76. End Function
  77.  
  78. Public Function GetININumber(Section As String, Key As String, Optional Default As Long = 0) As Long
  79. 'retrieves numeric value
  80.     GetININumber = GetPrivateProfileInt(Section, Key, Default, "drqcr.ini")
  81. End Function
  82.